/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;


import java.util.Iterator;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.widgets.Canvas;


/**
 *
 * @author Oren
 */
public class DrawEnvironment implements PaintListener{
	Simulation sim ;
        Boxes boxes ;
	public DrawEnvironment(Simulation sim, Boxes boxes){
		this.sim = sim;
                this.boxes = boxes;
	}

	// the drawing implemented method
	public void paintControl(PaintEvent e) {
		Canvas c=(Canvas)e.widget;	// get the canvas
		int maxX = c.getSize().x;	// max size
		int maxY = c.getSize().y;
		int mx=maxX/2,my=maxY/2;	// mid point as (0,0)

		e.gc.drawOval(mx-2, my-2, 4, 4);	// point at the middle.

                Iterator<Robot> robotit ;
                robotit = sim.getHashmap().iterator();
                while (robotit.hasNext())
                   robotit.next().paint(e);
                Iterator<Box> boxit ;
                boxit = boxes.getHashmap().iterator();
                while (boxit.hasNext())
                   boxit.next().paint(e);
	}
}
